<?php
// 通用后台导航栏（顶部+侧边栏）
if (!isset($settings)) {
    // 如果未加载系统设置，则加载
    require_once '../config.php';
    if (!function_exists('getSettings')) {
        function getSettings() {
            global $pdo;
            $settings = [];
            $stmt = $pdo->query("SELECT name, value FROM settings");
            while ($row = $stmt->fetch()) {
                $settings[$row['name']] = $row['value'];
            }
            return $settings;
        }
    }
    $settings = getSettings();
}
if (!isset($current_page)) {
    $current_page = '';
}

// 获取管理员信息
if (isset($_SESSION['admin_id'])) {
    $stmt = $pdo->prepare("SELECT * FROM admins WHERE id = ?");
    $stmt->execute([$_SESSION['admin_id']]);
    $admin = $stmt->fetch();
}
?>

<!--左侧导航-->
<aside class="lyear-layout-sidebar">
    <!-- logo -->
    <div id="logo" class="sidebar-header">
        <a href="index.php"><img src="../assets/images/logo-sidebar.png" title="<?php echo htmlspecialchars($settings['title']); ?>" alt="<?php echo htmlspecialchars($settings['title']); ?>" /></a>
    </div>
    <div class="lyear-layout-sidebar-info lyear-scroll">
        <nav class="sidebar-main">
            <ul class="nav-drawer">
                <li class="nav-item <?php echo ($current_page == 'index') ? 'active' : ''; ?>">
                    <a href="index.php">
                        <i class="mdi mdi-home-variant-outline"></i>
                        <span>控制面板</span>
                    </a>
                </li>
                <li class="nav-item <?php echo ($current_page == 'kami_generate') ? 'active' : ''; ?>">
                    <a href="kami_generate.php">
                        <i class="mdi mdi-key-plus"></i>
                        <span>生成卡密</span>
                    </a>
                </li>
                <li class="nav-item <?php echo ($current_page == 'kami_manage') ? 'active' : ''; ?>">
                    <a href="kami_manage.php">
                        <i class="mdi mdi-key-variant"></i>
                        <span>卡密列表</span>
                    </a>
                </li>
                 <li class="nav-item <?php echo ($current_page == 'product_manage') ? 'active' : ''; ?>">
                    <a href="product_manage.php">
                        <i class="mdi mdi-cart"></i>
                        <span>商品管理</span>
                    </a>
                </li>
                 <li class="nav-item <?php echo ($current_page == 'order_manage') ? 'active' : ''; ?>">
                    <a href="order_manage.php">
                        <i class="mdi mdi-format-list-bulleted"></i>
                        <span>订单列表</span>
                    </a>
                </li>
                <li class="nav-item <?php echo ($current_page == 'qb_query') ? 'active' : ''; ?>">
                    <a href="qb_query.php">
                        <i class="mdi mdi-file-find"></i>
                        <span>查询记录</span>
                    </a>
                </li>
                <li class="nav-item <?php echo ($current_page == 'settings') ? 'active' : ''; ?>">
                    <a href="settings.php">
                        <i class="mdi mdi-cog-outline"></i>
                        <span>系统设置</span>
                    </a>
                </li>
            </ul>
        </nav>
        
        <div class="sidebar-footer">
            <p class="copyright">Copyright &copy; <?php echo date('Y'); ?>. <a target="_blank" href="<?php echo htmlspecialchars($settings['site_url'] ?? '#'); ?>"><?php echo htmlspecialchars($settings['title']); ?></a> All rights reserved.</p>
        </div>
    </div>
</aside>
<!--End 左侧导航-->

<!--头部信息-->
<header class="lyear-layout-header">
    <nav class="navbar">
        <div class="navbar-left">
            <div class="lyear-aside-toggler">
                <span class="lyear-toggler-bar"></span>
                <span class="lyear-toggler-bar"></span>
                <span class="lyear-toggler-bar"></span>
            </div>
        </div>
        
        <ul class="navbar-right d-flex align-items-center">
            <li class="dropdown dropdown-profile">
                <a href="javascript:void(0)" data-bs-toggle="dropdown" class="dropdown-toggle">
                   
                    <span><?php echo isset($admin) ? htmlspecialchars($admin['username']) : 'Admin'; ?> <span class="caret"></span></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li>
                        <a class="dropdown-item" href="profile.php"><i class="mdi mdi-account-outline"></i> 个人信息</a>
                    </li>
                    <li>
                        <a class="dropdown-item" href="settings.php"><i class="mdi mdi-cog-outline"></i> 系统设置</a>
                    </li>
                    <li class="dropdown-divider"></li>
                    <li>
                        <a class="dropdown-item" href="logout.php"><i class="mdi mdi-logout-variant"></i> 退出登录</a>
                    </li>
                </ul>
            </li>
        </ul>
    </nav>
</header>
<!--End 头部信息--> 